import * as PIXI from 'pixi.js';
import { pb } from '../pb';
import Card from './card';
import ImagesService from './images-service';
export default class Images {
  container = new PIXI.Container()
  private cards: Card[];
  constructor(
    private data: pb.IImages,
    private is: ImagesService,
    private ticker: PIXI.Ticker,
  ) { }
  async reset() {
    this.container.removeChild();
    this.cards = []
    if (!this.data.urls || !this.data.urls.length) return;
    for (const u of this.data.urls) {
      const c = new Card(this.cards, this.data.time, this.ticker)
      this.cards.push(c)
      const s = await this.is.getSprite(u);
      s.x = 0;
      s.y = 0;
      s.width = this.data.width;
      s.height = this.data.height;
      c.container.addChild(s);
      this.container.addChild(c.container)
    }
    Card.home(this.cards, this.ticker)
  }
}
